package com.skplanet.oneplusonewindow.moimserver.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "MOIM_MEMBER")
public class Moim_Member  implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@Column(name = "pos")
	private String position;
	
	@Column(name = "userId")
	private long userId;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "moim_id")
	@JsonIgnore
	private Moim_Moim moim;
	
	@OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("id ASC" )
	private List<Moim_Board> boards;
	
	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public Moim_Moim getMoim() {
		return moim;
	}

	public void setMoim(Moim_Moim moim) {
		this.moim = moim;
	}

	public List<Moim_Board> getBoards() {
		return boards;
	}

	public void setBoards(List<Moim_Board> boards) {
		this.boards = boards;
	}
	
	public void addBoard(Moim_Board board) {
		if(this.boards == null) {
			this.boards = new ArrayList<Moim_Board>();
			this.boards.add(board);
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

		
}
